package PTA_JAVA.JavaB.Javademo15;

import java.time.LocalDate;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] types = {"Student","Teacher"};
        //输入种子seed，并用其初始化Random对象
        int seed = Integer.parseInt(sc.nextLine());
        Random random = new Random(seed);
        //输入对象生成数量n
        int n = Integer.parseInt(sc.nextLine());
        //以下是生成n个对象的循环
        Person[] p = new Person[n];

        for (int i = 0; i < n; i++) {
            String[] s = sc.nextLine().split(" ");
            //使用random.nextInt(2)从types数组中随机选取元素x并输出
            String x=types[random.nextInt(2)];
            //根据x选择输入相应的参数
            if(x.equals("Teacher")){
                Teacher tea= new Teacher(i, s[0], Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), s[4], Double.parseDouble(s[5]));
                System.out.println("Teacher");
                p[i]=tea;
            }else if(x.equals("Student")){
                Student stu = new Student(i, s[0], Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), Integer.parseInt(s[4]), s[5]);
                System.out.println("Student");
                p[i]=stu;
            }
        }
        //n个对象的"id,name,birthdate"
        for(Person i:p){
            System.out.println(i.getId()+","+i.getName()+","+i.getBirthDate());
        }
        //输出数组中的每个对象的toString
        for(Person i:p){
            System.out.println(i.toString());
        }
    }
}
class Person{
    private int id;
    private String name;
    private LocalDate birthDate;

    public Person(int id,String name,int year,int month,int dayOfMonth) {
        this.id = id;
        this.name = name;
        this.birthDate = LocalDate.parse(year+"-"+String.format("%02d",month)+"-"+String.format("%02d",dayOfMonth));
    }


    public int getId() {
        return id;
    }

    public LocalDate getBirthDate() {
        return birthDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person [" +
                "id=" + id +
                ", name=" + name +
                ", birthDate=" + birthDate +
                ']';
    }
}
class Student extends Person{
    private int enrollmentYear;
    private String clazzName;

    public Student(int id,String name,int year,int month,int dayOfMonth,int enrollmentYear,String clazzName) {
        super(id,name,year,month,dayOfMonth);
        this.enrollmentYear = enrollmentYear;
        this.clazzName = clazzName;
    }

    @Override
    public String toString() {

        return super.toString()+"\n"+"Student [" +
                "enrollmentYear=" + enrollmentYear +
                ", clazzName=" + clazzName  +
                ']';
    }
}
class Teacher extends Person{
    private String department;
    private double salary;
    public Teacher(int id, String name, int year, int month, int dayOfMonth,String department,double salary) {
        super(id, name, year, month, dayOfMonth);
        this.department = department;
        this.salary = salary;
    }

    @Override
    public String toString() {
        return super.toString()+"\n"+"Teacher [" +
                "department=" + department +
                ", salary=" + salary +
                ']';
    }
}
